#include "image_tools.hpp"

namespace ImageTools
{
    int rgb888_to_bayer_rggb16(uint8_t *rgb_image, uint16_t *bayer_image, const uint32_t HEIGHT, const uint32_t WIDTH)
    {
        int x, y;
        for (y = 0; y < HEIGHT; y++) {
            for (x = 0; x < WIDTH; x++) {
                int rgb_index = (y * WIDTH + x) * 3;  // RGB 图像的索引
                int bayer_index = y * WIDTH + x;      // Bayer 图像的索引
                
                uint8_t r = rgb_image[rgb_index];
                uint8_t g = rgb_image[rgb_index + 1];
                uint8_t b = rgb_image[rgb_index + 2];

                // Bayer RGGB 排列
                if (y % 2 == 0 && x % 2 == 0) {
                    bayer_image[bayer_index] = r << 8; // Red
                } else if (y % 2 == 0 && x % 2 == 1) {
                    bayer_image[bayer_index] = g << 8; // Green
                } else if (y % 2 == 1 && x % 2 == 0) {
                    bayer_image[bayer_index] = g << 8; // Green
                } else {
                    bayer_image[bayer_index] = b << 8; // Blue
                }
            }
        }

        return 0;
    }
}